import BaseService from "./BaseService";



export default class SwanCloudService
    extends BaseService {

    /**
     * 由于init函数无返回值，所以直接通知链接成功
     * @param url 相当于环境ID
     * @param port 无用
     */
    connect() {
        window['swan'].cloud.init({
            env: this.url
        })
        this.onOpen()
    }



    sendData(message: net.SendMessage) {

        let self = this;
        let protoID = message.sendData.protoId
        let data = message.data
        console.log("QQCloudService sendData  protoID  ", protoID, ' data ', data)
        window['swan'].cloud.callFunction({
            // 需调用的云函数名
            name: protoID,
            // 传给云函数的参数
            data: data,
            success: function (res) {
                console.log('WXCloudService  success res  ', res)
                self.onData(res.result);

            },
            fail: function (res) {
                console.log('WXCloudService  fail res  ', res)
                self.onError(message);
            },
            complete: function (res) { },

        })
    }


    isReady() {
        return true;
    }
}